library(ggplot2)
library("tidygeocoder")
library(readxl)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(stringr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(viridis)
## Loading required package: viridisLite
library(ggpointdensity)
library(usmap)
library(maptools)
## Loading required package: sp
## The legacy packages maptools, rgdal, and rgeos, underpinning this package
## will retire shortly. Please refer to R-spatial evolution reports on
## https://r-spatial.org/r/2023/05/15/evolution4.html for details.
## This package is now running under evolution status 0
## Please note that 'maptools' will be retired during October 2023,
## plan transition at your earliest convenience (see
## https://r-spatial.org/r/2023/05/15/evolution4.html and earlier blogs
## for guidance);some functionality will be moved to 'sp'.
##  Checking rgeos availability: FALSE
library(rgdal)
## Please note that rgdal will be retired during October 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-7, (SVN revision 1203)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.5.2, released 2022/09/02
## Path to GDAL shared files: C:/Users/user/AppData/Local/R/win-library/4.2/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 8.2.1, January 1st, 2022, [PJ_VERSION: 821]
## Path to PROJ shared files: C:/Users/user/AppData/Local/R/win-library/4.2/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.6-1
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
## 
## Attaching package: 'ggmap'
## The following object is masked from 'package:tidygeocoder':
## 
##     geocode
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
source("https://raw.githubusercontent.com/iascchen/VisHealth/master/R/calendarHeat.R")
source("https://raw.githubusercontent.com/iascchen/VisHealth/master/R/calendarHeat.R")
if(!file.exists("Data")){dir.create("Data")}

We need to clean the address data in order to improve the geocoding function we will use later. To start I will parse the street number, name, type, and direction from the given data. Once the fields have been separated we can adjust any capitalization errors and combine the fields into a form usable by tidygeocoder.

if(!file.exists("Data/Raw data (pre-geocoding).csv")) {

# Load in the original data files
Raw_sales_data <- read_excel("Data/Sandia Sunrooms - Sales Data - Lead Perfection - 5.11.2023.xlsx")
Raw_prospect_data <- read_excel("Data/Sandia Sunrooms - Prospect Data - Lead Perfection - 5.11.2023.xlsx")

# We need to remove several fields from the given data set to protect the anonymity of our clients
Raw_sales_data <- Raw_sales_data %>% select(-FirstName, -LastName, -Phone, -Phone2)
Raw_prospect_data <- Raw_prospect_data %>% rename("id" = "CustNumber",
                                                  "productid" = "Productid",
                                                  "SubSource" = "SourceSubDescr")
Raw_prospect_data$id <- as.numeric(as.character(Raw_prospect_data$id))

# Combine the two data sets into a single data frame consisting of all sales and prospect information
Raw_data <- dplyr::bind_rows(Raw_sales_data, Raw_prospect_data)
  # Convert the address column to upper case to help type and direction recognition
Raw_data$Address1 <- toupper(Raw_data$Address1)

# Regular expression for each component we need to strip
number_regex <- "^\\d+"
street_regex <- "\\b[A-Za-z]+(\\s+(?!ST|AVE|BLVD|DR|CT|LN|RD|WAY|CIR|TER|HWY|NE|SE|NW|SW)[A-Za-z]+)*\\b"
type_regex <- "\\b(?:ST|AVE|BLVD|DR|CT|LN|RD|WAY|CIR|PL|TER|HWY)\\b"
direction_regex <- "\\b(?:N|S|E|W|NE|SE|NW|SW)\\b"

# Extract each component and add the value as a new column
Raw_data['StreetNumber'] <- str_extract(Raw_data$Address1, number_regex)
Raw_data <- Raw_data %>% relocate(StreetNumber, .before = City)

Raw_data['StreetName'] <- str_extract(Raw_data$Address1, street_regex)
Raw_data <- Raw_data %>% relocate(StreetName, .before = City)

Raw_data['StreetType'] <- str_extract(Raw_data$Address1, type_regex)
Raw_data <- Raw_data %>% relocate(StreetType, .before = City)

Raw_data['StreetDirection'] <- str_extract(Raw_data$Address1, direction_regex)
Raw_data <- Raw_data %>% relocate(StreetDirection, .before = City)

# Convert StreetName and StreetType back to title case to correct grammar
Raw_data$StreetName <- str_to_title(Raw_data$StreetName)
Raw_data$StreetType <- str_to_title(Raw_data$StreetType)

# Set the value of Address2 equal to the form
# "StreetNumber" "StreetName" "StreetType" "Direction" "City", "State" "Zipcode"

# Create a new data frame to combine all columns while omitting NA values.
AddressPart1 <- data.frame(Raw_data$StreetNumber, Raw_data$StreetName, Raw_data$StreetType, Raw_data$StreetDirection)
AddressPart1$FullAddress <- apply(AddressPart1, 1, function(x) paste(x[!is.na(x)], collapse = " "))

# Reassign the combined address to Address2 in Raw_data and then past in the city, state and zip with commas
Raw_data$Address2 <- AddressPart1$FullAddress
Raw_data$Address2 <- paste(Raw_data$Address2, ", ", Raw_data$City, ", ", Raw_data$State, Raw_data$Zip)
Raw_data <- Raw_data %>% rename('FullAddress' = 'Address2')
Raw_data$StreetName <- AddressPart1$FullAddress

# Create a new data frame to geocode the address information
Raw_Geo_data <- data.frame(AddressPart1$FullAddress, Raw_data$City, Raw_data$State, Raw_data$Zip)

# Remove all the redundant data fields created in cleaning this portion of the data
Raw_data <- Raw_data %>% select(-StreetNumber, -StreetType, -StreetDirection, -Address1)
rm(AddressPart1)

# Export the cleaned data to CSV files in the data folder
write.csv(Raw_Geo_data, "Data/Data for export to Geocodio.csv", row.names=FALSE)
write.csv(Raw_data, "Data/Raw data (pre-geocoding).csv", row.names=FALSE)
}

The next step in the data cleaning process is to create a new field for the latitude and longitude of each address in our data set. Using the tidygeocoder package in R we can input an address and receive the associated latitude and longitude for each data point. This information can then be passed into the Google maps API for further analysis.

if(!file.exists("Data/Geolocated Data - Sales & Prospect - 5.11.2023.csv")) {
  
# Load the previously created csv files in preparation for merging
Temp_data <- read.csv("Data/Geocoded Addresses.csv")
Pre_Geo <- read.csv("Data/Raw data (pre-geocoding).csv")

# Remove unneeded columns from geo-data
Temp_data <- Temp_data[-c(2:5,10:19)]

# Combine the two data sets and save to file
Comb_data <- cbind(Pre_Geo, Temp_data[c("Latitude", "Longitude", "Accuracy.Score", "Accuracy.Type")])
write.csv(Comb_data, "Data/Geolocated Data - Sales & Prospect - 5.11.2023.csv", row.names=FALSE)
}
Data <- read.csv("Data/Geolocated Data - Sales & Prospect - 5.11.2023.csv")

# Remove all data fields taht do not have a contract date
Sales <- subset(Data, (!is.na(Data$ContractDate)))
Prospect <- subset(Data, (is.na(Data$ContractDate)))

# Remove all data points with a negative sale value
Sales <- Sales[Sales$GrossAmount >= 0,]

# Isolate each city into its own dataframe
ABQ_sales <- subset(Sales, Sales$City == "Albuquerque")
RR_sales <- subset(Sales, Sales$City == "Rio Rancho")
SF_sales <- subset(Sales, Sales$City == "Santa Fe")

# Combine the ABW and RR data into a single Metro area
Metro_sales <- dplyr::bind_rows(ABQ_sales, RR_sales)
Sales$ContractDate <- mdy(Sales$ContractDate)
Metro_sales$ContractDate <- mdy(Metro_sales$ContractDate)
SF_sales$ContractDate <- mdy(SF_sales$ContractDate)
RR_sales$ContractDate <- mdy(RR_sales$ContractDate)
ABQ_sales$ContractDate <- mdy(ABQ_sales$ContractDate)
Prospect$DateAdded <- mdy(Prospect$DateAdded)
## Warning: 37595 failed to parse.
# Create sub categories for each type of product in a city
ABQ_PC_sales <- subset(ABQ_sales, ABQ_sales$productid == "PC")
ABQ_Bath_sales <- subset(ABQ_sales, ABQ_sales$productid == "Bath")
ABQ_Sun_sales <- subset(ABQ_sales, ABQ_sales$productid == "Sun")
ABQ_Kitchen_sales <- subset(ABQ_sales, ABQ_sales$productid == "Kitchen")
ABQ_Win_sales <- subset(ABQ_sales, ABQ_sales$productid == "Win")

RR_PC_sales <- subset(RR_sales, RR_sales$productid == "PC")
RR_Bath_sales <- subset(RR_sales, RR_sales$productid == "Bath")
RR_Sun_sales <- subset(RR_sales, RR_sales$productid == "Sun")
RR_Kitchen_sales <- subset(RR_sales, RR_sales$productid == "Kitchen")
RR_Win_sales <- subset(RR_sales, RR_sales$productid == "Win")

SF_PC_sales <- subset(SF_sales, SF_sales$productid == "PC")
SF_Bath_sales <- subset(SF_sales, SF_sales$productid == "Bath")
SF_Sun_sales <- subset(SF_sales, SF_sales$productid == "Sun")
SF_Kitchen_sales <- subset(SF_sales, SF_sales$productid == "Kitchen")
SF_Win_sales <- subset(SF_sales, SF_sales$productid == "Win")

Metro_PC_sales <- subset(Metro_sales, Metro_sales$productid == "PC")
Metro_Bath_sales <- subset(Metro_sales, Metro_sales$productid == "Bath")
Metro_Sun_sales <- subset(Metro_sales, Metro_sales$productid == "Sun")
Metro_Kitchen_sales <- subset(Metro_sales, Metro_sales$productid == "Kitchen")
Metro_Win_sales <- subset(Metro_sales, Metro_sales$productid == "Win")
earth.dist <- function (long1, lat1, long2, lat2) {
  rad <- pi/180
  a1 <- lat1 * rad
  a2 <- long2 * rad
  b1 <- lat2 * rad
  b2 <- long2 * rad
  dlon <- b2 - a2
  dlat <- b1 - a1
  
  a <- (sin(dlat/2))^2 + cos(a1) * cos(b1) * (sin(dlon/2))^2
  c <- 2 * atan2(sqrt(a), sqrt(1 - a))
  R <-6378.145
  d <- R * c
  return(d)
}
# Add empty column to each set of sales/prospect data
RR_sales['Distance'] <- NA
ABQ_sales['Distance'] <- NA
SF_sales['Distance'] <- NA

# Calculate distance from the calculated center of each area
RR_sales$Distance <- earth.dist(RR_sales$Longitude,
                                RR_sales$Latitude,
                                mean(RR_sales$Longitude),
                                mean(RR_sales$Latitude))
ABQ_sales$Distance <- earth.dist(ABQ_sales$Longitude,
                                ABQ_sales$Latitude,
                                mean(ABQ_sales$Longitude),
                                mean(ABQ_sales$Latitude))
SF_sales$Distance <- earth.dist(SF_sales$Longitude,
                                SF_sales$Latitude,
                                mean(SF_sales$Longitude),
                                mean(SF_sales$Latitude))

# Filter results farther than X miles from the center of the area
RR_sales <- RR_sales[RR_sales$Distance <= 10,] 
ABQ_sales <- ABQ_sales[ABQ_sales$Distance <= 15,]
SF_sales <- SF_sales[SF_sales$Distance <= 20,]
if (!file.exists("Maps/NM_map.RData")){
NM <- ggmap(get_googlemap(center = c(lon = -106.018066, lat =34.307144),
                          zoom = 7, scale = 2, 
                          maptype = 'roadmap', 
                          color = 'color'))
save(NM, file = "Maps/NM_map.RData")
}

if (!file.exists("Maps/Metro_map.RData")){
Metro <- ggmap(get_googlemap(center = c(lon = mean(Metro_sales$Longitude), mean(Metro_sales$Latitude)),
                          zoom = 11, scale = 1, 
                          maptype = 'roadmap', 
                          color = 'color'))
save(Metro, file = "Maps/Metro_map.RData")
}

if (!file.exists("Maps/RR_map.RData")){
RR <- ggmap(get_googlemap(center = c(lon = mean(RR_sales$Longitude), mean(RR_sales$Latitude)),
                          zoom = 12, scale = 1, 
                          maptype = 'roadmap', 
                          color = 'color'))
save(RR, file = "Maps/RR_map.RData")
}

if (!file.exists("Maps/SFcounty_map.RData")){
SFcounty <- ggmap(get_googlemap(center = c(lon = mean(SF_sales$Longitude), mean(SF_sales$Latitude)),
                          zoom = 11, scale = 1, 
                          maptype = 'roadmap', 
                          color = 'color'))
save(SFcounty, file = "Maps/SFcounty_map.RData")
}

if (!file.exists("Maps/SF_map.RData")){
SF <- ggmap(get_googlemap(center = c(lon = mean(SF_sales$Longitude), mean(SF_sales$Latitude)),
                          zoom = 12, scale = 1, 
                          maptype = 'roadmap', 
                          color = 'color'))
save(SF, file = "Maps/SF_map.RData")
}
load(file = "Maps/Metro_map.RData")
load(file = "Maps/NM_map.RData")
load(file = "Maps/RR_map.RData")
load(file = "Maps/SF_map.RData")
load(file = "Maps/SFcounty_map.RData")
library(dplyr)

# Stats for SF
SF_sales_by_zip <- SF_sales %>%
  group_by(Zip) %>%
  summarize(
    count = n(),
    med_Amount = median(GrossAmount),
    med_lat = mean(Latitude),
    med_long = mean(Longitude)
  )
head(SF_sales_by_zip)
## # A tibble: 6 × 5
##   Zip   count med_Amount med_lat med_long
##   <chr> <int>      <dbl>   <dbl>    <dbl>
## 1 87101     1     14988.    35.7    -106.
## 2 87501    76      8181.    35.7    -106.
## 3 87502     2     11692.    35.6    -106.
## 4 87504     2      1954.    35.7    -106.
## 5 87505   157     10080.    35.6    -106.
## 6 87506    29     14251     35.7    -106.
# Stats for RR
RR_sales_by_zip <- RR_sales %>%
  group_by(Zip) %>%
  summarize(
    count = n(),
    med_Amount = median(GrossAmount),
    med_lat = mean(Latitude),
    med_long = mean(Longitude)
  )
head(RR_sales_by_zip)
## # A tibble: 6 × 5
##   Zip   count med_Amount med_lat med_long
##   <chr> <int>      <dbl>   <dbl>    <dbl>
## 1 87112     2      6138.    35.2    -107.
## 2 87114     3      8535     35.3    -107.
## 3 87123     1      2489     35.2    -107.
## 4 87124   673      7800     35.3    -107.
## 5 87144   501      9275     35.3    -107.
## 6 87174     1      3265     35.3    -107.
# Stats for Metro
Metro_sales_by_zip <- Metro_sales %>%
  group_by(Zip) %>%
  summarize(
    count = n(),
    med_Amount = median(GrossAmount),
    med_lat = mean(Latitude),
    med_long = mean(Longitude)
  )
head(Metro_sales_by_zip)
## # A tibble: 6 × 5
##   Zip   count med_Amount med_lat med_long
##   <chr> <int>      <dbl>   <dbl>    <dbl>
## 1 87008     1     19381     35.1    -106.
## 2 87035     1      5464     34.9    -106.
## 3 87102    24      7808.    35.1    -107.
## 4 87103     1      4440     35.1    -107.
## 5 87104    35      8750     35.1    -107.
## 6 87105   134      7470.    35.0    -107.
# Stats for Sales
Sales_by_zip <- Sales %>%
  group_by(Zip) %>%
  summarize(
    count = n(),
    med_Amount = median(GrossAmount),
    med_lat = mean(Latitude),
    med_long = mean(Longitude)
  )
head(Sales_by_zip)
## # A tibble: 6 × 5
##   Zip   count med_Amount med_lat med_long
##   <chr> <int>      <dbl>   <dbl>    <dbl>
## 1 81144     1     35289     37.6    -106.
## 2 86515     1     26502     35.7    -109.
## 3 87001     8      6694.    35.4    -106.
## 4 87002    71      8075     34.7    -107.
## 5 87004    90      6456.    35.3    -107.
## 6 87006     2      9780     34.7    -107.
# Stats for Prospect
Prospect_by_zip <- Prospect %>%
  group_by(Zip) %>%
  summarize(
    count = n(),
    med_Amount = median(GrossAmount),
    med_lat = mean(Latitude),
    med_long = mean(Longitude)
  )
head(Prospect_by_zip)
## # A tibble: 6 × 5
##   Zip   count med_Amount med_lat med_long
##   <chr> <int>      <dbl>   <dbl>    <dbl>
## 1 05720     1         NA     0        0  
## 2 10001     1         NA    40.8    -74.0
## 3 10002     1         NA    40.7    -74.0
## 4 10004     1         NA    40.7    -74.0
## 5 10304     1         NA    40.6    -74.1
## 6 10567     1         NA    41.3    -73.9
SF +
  geom_pointdensity(aes(x = Longitude,
                    y = Latitude),
                    data = SF_sales,
                    size = 1,
                    adjust = .05) +
  scale_color_viridis()
## Warning: Removed 86 rows containing non-finite values (`stat_pointdensity()`).

RR + 
  geom_pointdensity(aes(x = Longitude, y = Latitude),
                    data = RR_sales,
                    size = 1,
                    adjust = .01) +
  scale_color_viridis()
## Warning: Removed 37 rows containing non-finite values (`stat_pointdensity()`).

Metro +
  geom_pointdensity(aes(x = Longitude, y = Latitude),
                    data = ABQ_sales,
                    size = .5,
                    adjust = .01) +
  scale_color_viridis()
## Warning: Removed 5 rows containing non-finite values (`stat_pointdensity()`).

Metro +
  geom_pointdensity(aes(x = Longitude, y = Latitude),
                    data = Metro_sales,
                    size = .5,
                    adjust = .01)+
  scale_color_viridis()
## Warning: Removed 154 rows containing non-finite values (`stat_pointdensity()`).

NM +
  geom_pointdensity(aes(x = Longitude, y = Latitude),
                    data = Sales,
                    size = .5,
                    adjust = .001) +
  scale_color_viridis()
## Warning: Removed 1 rows containing non-finite values (`stat_pointdensity()`).

summary(Sales)
##        id         productid          GrossAmount      ContractDate       
##  Min.   :    1   Length:7846        Min.   :     0   Min.   :1999-10-09  
##  1st Qu.: 3577   Class :character   1st Qu.:  4764   1st Qu.:2005-12-20  
##  Median : 7056   Mode  :character   Median :  8208   Median :2010-05-17  
##  Mean   : 7446                      Mean   : 12134   Mean   :2011-01-30  
##  3rd Qu.:11179                      3rd Qu.: 15422   3rd Qu.:2016-06-29  
##  Max.   :17269                      Max.   :122703   Max.   :2023-05-10  
##  FullAddress         StreetName            City              State          
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Zip             JobStatus         SalesRepName1      SalesRepName2     
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Source           SubSource          DateAdded            Issued         
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Sat               Latitude       Longitude      Accuracy.Score  
##  Length:7846        Min.   :32.21   Min.   :-109.1   Min.   :0.4000  
##  Class :character   1st Qu.:35.09   1st Qu.:-106.7   1st Qu.:1.0000  
##  Mode  :character   Median :35.16   Median :-106.6   Median :1.0000  
##                     Mean   :35.19   Mean   :-106.5   Mean   :0.9529  
##                     3rd Qu.:35.26   3rd Qu.:-106.5   3rd Qu.:1.0000  
##                     Max.   :37.58   Max.   :-103.1   Max.   :1.0000  
##  Accuracy.Type     
##  Length:7846       
##  Class :character  
##  Mode  :character  
##                    
##                    
## 
p1 = calendarHeat(
  Sales$ContractDate,
  Sales$GrossAmount,
  color = 'r2b',
  ncolors = 25,
  varname = "Historic Sales Seasonality"
)
## Loading required package: lattice
## Loading required package: grid
## Loading required package: chron
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'chron'

## Warning in trellis.panelArgs(): Plot spans multiple pages, only last page can
## be updated

summary(Sales)
##        id         productid          GrossAmount      ContractDate       
##  Min.   :    1   Length:7846        Min.   :     0   Min.   :1999-10-09  
##  1st Qu.: 3577   Class :character   1st Qu.:  4764   1st Qu.:2005-12-20  
##  Median : 7056   Mode  :character   Median :  8208   Median :2010-05-17  
##  Mean   : 7446                      Mean   : 12134   Mean   :2011-01-30  
##  3rd Qu.:11179                      3rd Qu.: 15422   3rd Qu.:2016-06-29  
##  Max.   :17269                      Max.   :122703   Max.   :2023-05-10  
##  FullAddress         StreetName            City              State          
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Zip             JobStatus         SalesRepName1      SalesRepName2     
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Source           SubSource          DateAdded            Issued         
##  Length:7846        Length:7846        Length:7846        Length:7846       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Sat               Latitude       Longitude      Accuracy.Score  
##  Length:7846        Min.   :32.21   Min.   :-109.1   Min.   :0.4000  
##  Class :character   1st Qu.:35.09   1st Qu.:-106.7   1st Qu.:1.0000  
##  Mode  :character   Median :35.16   Median :-106.6   Median :1.0000  
##                     Mean   :35.19   Mean   :-106.5   Mean   :0.9529  
##                     3rd Qu.:35.26   3rd Qu.:-106.5   3rd Qu.:1.0000  
##                     Max.   :37.58   Max.   :-103.1   Max.   :1.0000  
##  Accuracy.Type     
##  Length:7846       
##  Class :character  
##  Mode  :character  
##                    
##                    
## 
p2 = calendarHeat(
  ABQ_sales$ContractDate,
  ABQ_sales$GrossAmount,
  color = 'r2b',
  ncolors = 25,
  varname = "Total Sales in Albuquerque"
)
## Loading required package: chron
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'chron'

## Warning in trellis.panelArgs(): Plot spans multiple pages, only last page can
## be updated

summary(ABQ_sales)
##        id         productid          GrossAmount      ContractDate       
##  Min.   :    2   Length:4263        Min.   :     0   Min.   :1999-10-13  
##  1st Qu.: 3126   Class :character   1st Qu.:  4163   1st Qu.:2005-04-28  
##  Median : 6744   Mode  :character   Median :  7304   Median :2010-02-23  
##  Mean   : 7235                      Mean   : 11070   Mean   :2010-10-31  
##  3rd Qu.:11108                      3rd Qu.: 13616   3rd Qu.:2016-05-08  
##  Max.   :17269                      Max.   :122703   Max.   :2023-05-10  
##  FullAddress         StreetName            City              State          
##  Length:4263        Length:4263        Length:4263        Length:4263       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Zip             JobStatus         SalesRepName1      SalesRepName2     
##  Length:4263        Length:4263        Length:4263        Length:4263       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Source           SubSource          DateAdded            Issued         
##  Length:4263        Length:4263        Length:4263        Length:4263       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Sat               Latitude       Longitude      Accuracy.Score 
##  Length:4263        Min.   :34.99   Min.   :-106.9   Min.   :0.410  
##  Class :character   1st Qu.:35.09   1st Qu.:-106.7   1st Qu.:1.000  
##  Mode  :character   Median :35.13   Median :-106.6   Median :1.000  
##                     Mean   :35.13   Mean   :-106.6   Mean   :0.965  
##                     3rd Qu.:35.17   3rd Qu.:-106.5   3rd Qu.:1.000  
##                     Max.   :35.25   Max.   :-106.2   Max.   :1.000  
##  Accuracy.Type         Distance        
##  Length:4263        Min.   : 0.000357  
##  Class :character   1st Qu.: 2.199843  
##  Mode  :character   Median : 4.203184  
##                     Mean   : 4.625324  
##                     3rd Qu.: 6.973595  
##                     Max.   :14.842001
p3 = calendarHeat(
  ABQ_PC_sales$ContractDate,
  ABQ_PC_sales$GrossAmount,
  color = 'r2b',
  ncolors = 25,
  varname = "Patio Cover Sales in Albuquerque"
)
## Loading required package: chron
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'chron'

## Warning in trellis.panelArgs(): Plot spans multiple pages, only last page can
## be updated

summary(ABQ_PC_sales)
##        id         productid          GrossAmount      ContractDate       
##  Min.   :    5   Length:1721        Min.   :     0   Min.   :1999-11-03  
##  1st Qu.: 2399   Class :character   1st Qu.:  3466   1st Qu.:2004-07-24  
##  Median : 5761   Mode  :character   Median :  5300   Median :2008-11-28  
##  Mean   : 6416                      Mean   :  6476   Mean   :2009-10-23  
##  3rd Qu.: 9680                      3rd Qu.:  7806   3rd Qu.:2015-02-12  
##  Max.   :17236                      Max.   :100528   Max.   :2023-03-17  
##  FullAddress         StreetName            City              State          
##  Length:1721        Length:1721        Length:1721        Length:1721       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Zip             JobStatus         SalesRepName1      SalesRepName2     
##  Length:1721        Length:1721        Length:1721        Length:1721       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Source           SubSource          DateAdded            Issued         
##  Length:1721        Length:1721        Length:1721        Length:1721       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##      Sat               Latitude       Longitude      Accuracy.Score  
##  Length:1721        Min.   :34.95   Min.   :-106.8   Min.   :0.4800  
##  Class :character   1st Qu.:35.09   1st Qu.:-106.7   1st Qu.:1.0000  
##  Mode  :character   Median :35.13   Median :-106.6   Median :1.0000  
##                     Mean   :35.13   Mean   :-106.6   Mean   :0.9656  
##                     3rd Qu.:35.17   3rd Qu.:-106.5   3rd Qu.:1.0000  
##                     Max.   :35.27   Max.   :-106.2   Max.   :1.0000  
##  Accuracy.Type     
##  Length:1721       
##  Class :character  
##  Mode  :character  
##                    
##                    
## 
citation("ggmap")
## 
## To cite package 'ggmap' in publications use:
## 
##   D. Kahle and H. Wickham. ggmap: Spatial Visualization with ggplot2.
##   The R Journal, 5(1), 144-161. URL
##   http://journal.r-project.org/archive/2013-1/kahle-wickham.pdf
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     author = {David Kahle and Hadley Wickham},
##     title = {ggmap: Spatial Visualization with ggplot2},
##     journal = {The R Journal},
##     year = {2013},
##     volume = {5},
##     number = {1},
##     pages = {144--161},
##     url = {https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf},
##   }
sessionInfo()
## R version 4.2.2 (2022-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19045)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8 
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] lattice_0.20-45      lubridate_1.9.2      ggmap_3.0.2         
##  [4] rgdal_1.6-7          maptools_1.1-7       sp_1.6-1            
##  [7] usmap_0.6.2          ggpointdensity_0.1.0 viridis_0.6.3       
## [10] viridisLite_0.4.2    tidyr_1.3.0          stringr_1.5.0       
## [13] dplyr_1.1.2          readxl_1.4.2         tidygeocoder_1.0.5  
## [16] ggplot2_3.4.2       
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.0    xfun_0.39           bslib_0.5.0        
##  [4] purrr_1.0.1         colorspace_2.1-0    vctrs_0.6.2        
##  [7] generics_0.1.3      htmltools_0.5.5     yaml_2.3.7         
## [10] utf8_1.2.3          rlang_1.1.1         jquerylib_0.1.4    
## [13] pillar_1.9.0        foreign_0.8-83      glue_1.6.2         
## [16] withr_2.5.0         plyr_1.8.8          jpeg_0.1-10        
## [19] lifecycle_1.0.3     munsell_0.5.0       gtable_0.3.3       
## [22] cellranger_1.1.0    RgoogleMaps_1.4.5.3 evaluate_0.21      
## [25] labeling_0.4.2      knitr_1.43          fastmap_1.1.1      
## [28] fansi_1.0.4         highr_0.10          Rcpp_1.0.10        
## [31] scales_1.2.1        cachem_1.0.8        jsonlite_1.8.5     
## [34] farver_2.1.1        gridExtra_2.3       png_0.1-8          
## [37] digest_0.6.31       stringi_1.7.12      bitops_1.0-7       
## [40] cli_3.6.1           tools_4.2.2         magrittr_2.0.3     
## [43] sass_0.4.6          tibble_3.2.1        pkgconfig_2.0.3    
## [46] timechange_0.2.0    httr_1.4.6          rmarkdown_2.22     
## [49] rstudioapi_0.14     R6_2.5.1            compiler_4.2.2